package com.cw.jeeyt.service.converter.api;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.api.ApiTableAbbreviationBo;
import com.cw.jeeyt.dao.model.api.ApiTableAbbreviationDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 数据库表缩写配置转换类
 *
 * @author chenw
 * @date 2019-04-17 13:17:14
 */
public class ApiTableAbbreviationConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static ApiTableAbbreviationBo do2Bo(ApiTableAbbreviationDo model) {
        ApiTableAbbreviationBo bo = new ApiTableAbbreviationBo();
        if (model == null) {
            return bo;
        }
        bo.setId(model.getId());
        bo.setDatabaseId(model.getDatabaseId());
        bo.setTableCode(model.getTableCode());
        bo.setTableName(model.getTableName());
        bo.setTableAbbreviation(model.getTableAbbreviation());
        bo.setPkConstraint(model.getPkConstraint());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static ApiTableAbbreviationDo bo2Do(ApiTableAbbreviationBo bo) {
        ApiTableAbbreviationDo model = new ApiTableAbbreviationDo();
        if (bo == null) {
            return model;
        }
        model.setId(bo.getId());
        model.setDatabaseId(bo.getDatabaseId());
        model.setTableCode(bo.getTableCode());
        model.setTableName(bo.getTableName());
        model.setTableAbbreviation(bo.getTableAbbreviation());
        model.setPkConstraint(bo.getPkConstraint());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<ApiTableAbbreviationBo> doList2BoList(List<ApiTableAbbreviationDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), ApiTableAbbreviationConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<ApiTableAbbreviationDo> boList2DoList(List<ApiTableAbbreviationBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), ApiTableAbbreviationConverter::bo2Do));
    }
}